package rdatabase

import (
	"encoding/json"
	"log"
	"os"
)

type Password struct {
	MySQL         accountAndPassword `json:"mysql"`
	Redis         accountAndPassword `json:"redis"`
	MongoDB       accountAndPassword `json:"mongo_db"`
	JwtSecretKey  string             `json:"jwt_secret_key"`
	JwtRefreshKey string             `json:"jwt_refresh_key"`
	PwdSecretKey  string             `json:"pwd_secret_key"`
}

type accountAndPassword struct {
	IP       string `json:"ip"`
	Account  string `json:"account"`
	Password string `json:"Password"`
	Port     uint   `json:"port"`
	Other    string `json:"other"`
}

func ReadPassword(passwordSrc string) *Password {
	content, err := os.ReadFile(passwordSrc)
	if err != nil {
		log.Fatal("读取密码文件", passwordSrc, "失败：", err)
	}
	var rt Password
	err = json.Unmarshal(content, &rt)
	if err != nil {
		log.Fatal("解码密码文件", passwordSrc, "失败：", err)
	}
	return &rt
}
